home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / cne / reslt1.exe / RESULTS.PAS < prev   
Pascal/Delphi Source File  |  1992-02-16  |  8KB  |  354 lines

  1. PROGRAM CNEResults;
  2.   (* Show progress on Novell's CNE Assessment Test V2.0. *)
  3.  
  4.   (*    Input : CNE~RSP.DAT - Response file to the CNE assessment Test. *)
  5.   (*    Output : RESULTS.RPT - An ASCII file which can be viewed or printed. *)
  6.  
  7.   (* INPUT RECORD LOOKS LIKE THIS: *)
  8.   (* ┌───┬──────────┬───┬─────────┬─────┬───┬─────────┬───┬───────┬────────┬───────┬────────┐ *)
  9.   (* │0Ch│FIRST_NAME│20h│LAST_NAME│0007h│63h│TEST_NAME│63h│SEC_NUM│00h..00h│ANSWERS│20h..20h│ *)
  10.   (* └───┴──────────┴───┴─────────┴─────┴───┴─────────┴───┴───────┴────────┴───────┴────────┘ *)
  11.  
  12.   (* VERSION HISTORY : *)
  13.   (* V1.00 2/16/92 - Initial version. Displays name, test, section, test results    *)
  14.   (*                    (whether correct answer or choice was incorrect, and score. *)
  15.   (*                 Author : Eric J.G. Bonnell 73500,3250.                         *)
  16.  
  17.   (* !!!!! NEXT Version Changes Go Here !!!!!!!!! *)
  18.  
  19.  
  20. USES
  21.      Crt;
  22.        (* Standard I/O *)
  23.  
  24.  
  25. CONST
  26.      NUL : Char = #$00;
  27.      Preamble : Char = #$0C;
  28.      Space : Char = #$20;
  29.      ResponseHeader : Char = #$07;
  30.      Letter_c : Char = #$63;
  31.  
  32.      NessessaryCredits
  33.         = 'Compiled Using Turbo Pascal V6.0 (c) 1983,90 Borland International, Inc.';
  34.  
  35.  
  36. VAR
  37.    InFile : Text;
  38.      (* CNE~RSP.DAT *)
  39.    OutFile : Text;
  40.      (* RESULTS.RPT *)
  41.  
  42.  
  43. PROCEDURE Salutations;
  44.   (* Write an opening message on the screen. *)
  45. BEGIN
  46.    WriteLn(ParamStr(0),' - CNE Assessment Test V2.0 Results.');
  47.    WriteLn('   V1.00 (c) 1992  Eric J.G. Bonnell  73500,3250.');
  48.    WriteLn('      May be altered, but must supply a new version number,');
  49.    WriteLn('         name, date and version history documentation!');
  50.    WriteLn
  51. END (* Salutations *);
  52.  
  53.  
  54. PROCEDURE Goodbyes;
  55.   (* Let user know it is done. *)
  56. BEGIN
  57.    WriteLn('Finished. Results are recorded in RESULTS.RPT.');
  58.    WriteLn
  59. END (* GoodByes *);
  60.  
  61.  
  62. FUNCTION IsAlpha(C : Char) : Boolean;
  63.   (* True if C is alphabetic. *)
  64. BEGIN
  65.    IsAlpha := C IN ['A'..'Z','a'..'z']
  66. END (* IsAlpha *);
  67.  
  68.  
  69. FUNCTION IsNumeric(C : Char) : Boolean;
  70.   (* True if C is a decimal digit. *)
  71. BEGIN
  72.    IsNumeric:= C IN ['0'..'9']
  73. END (* IsNumeric *);
  74.  
  75.  
  76. FUNCTION IsPreamble(C : Char) : Boolean;
  77.   (* True if C is 0Ch. *)
  78. BEGIN
  79.    IsPreamble:= C = Preamble
  80. END (* IsPreamble *);
  81.  
  82.  
  83. FUNCTION IsSpace(C : Char) : Boolean;
  84.   (* True if C is 20h. *)
  85. BEGIN
  86.    IsSpace := C = Space
  87. END (* IsSpace *);
  88.  
  89.  
  90. FUNCTION IsNul(C : Char) : Boolean;
  91.   (* True if C is 00h. *)
  92. BEGIN
  93.    IsNul := C = NUL
  94. END (* IsNul *);
  95.  
  96.  
  97. FUNCTION IsCntrl(C : Char) : Boolean;
  98.   (* True if C is not alphanumeric (not nessessarily a control character). *)
  99. BEGIN
  100.    IsCntrl := NOT IsAlpha(C) AND NOT IsNumeric(C)
  101. END (* IsCntrl *);
  102.  
  103.  
  104. FUNCTION IsResponseHeader(C : Char) : Boolean;
  105.   (* True if C iss 07h. *)
  106. BEGIN
  107.    IsResponseHeader := C = ResponseHeader
  108. END (* IsResponseHeader *);
  109.  
  110.  
  111. FUNCTION IsLetter_c(C : Char) : Boolean;
  112.   (* True if C is a lowercase letter 'c'. *)
  113. BEGIN
  114.    IsLetter_c := C = Letter_c
  115. END (* IsLetter_c *);
  116.  
  117.  
  118. FUNCTION UpperCase(S : String) : String;
  119.   (* Convert S to all upper case characters. *)
  120. VAR
  121.    I : 0..255;
  122. BEGIN
  123.    I := Length(S);
  124.    WHILE I > 0 DO
  125.       BEGIN
  126.          S[I] := UpCase(S[I]);
  127.          Dec(I)
  128.       END;
  129.    UpperCase := S
  130. END (* UpperCase *);
  131.  
  132.  
  133. FUNCTION NoMore(VAR F : Text) : Boolean;
  134.   (* True if end-of-file found, otherwise found next record. *)
  135. VAR
  136.    C : Char;
  137. BEGIN
  138.    C := #$FF;
  139.    REPEAT
  140.       Read(F,C);
  141.       NoMore := EoF(F)
  142.    UNTIL IsPreamble(C) OR EoF(F)
  143. END (* NoMore *);
  144.  
  145.  
  146. PROCEDURE OpenFiles(VAR F,
  147.                     O : Text);
  148.   (* Open input and output files. *)
  149. BEGIN
  150.    Assign(F,'CNE~RSP.DAT');
  151.    ReSet(F);
  152.    Assign(O,'RESULTS.RPT');
  153.    ReWrite(O)
  154. END (* OpenFiles *);
  155.  
  156.  
  157. PROCEDURE CloseFiles(VAR F,
  158.                      O : Text);
  159.   (* Close input and output files. *)
  160. BEGIN
  161.    Close(F);
  162.    Close(O)
  163. END (* CloseFiles *);
  164.  
  165.  
  166. FUNCTION FirstName(VAR F : Text) : String;
  167.   (* Retrieve FIRST_NAME from current record in file F. *)
  168. VAR
  169.    S : String;
  170.    C : Char;
  171. BEGIN
  172.    S := '';
  173.    C := #$00;
  174.    WHILE (NOT EoF(F)) AND (NOT IsSpace(C)) DO
  175.       BEGIN
  176.          Read(F,C);
  177.          S[0] := Chr(Ord(S[0]) + 1);
  178.          S[Ord(S[0])] := C
  179.       END;
  180.    FirstName := UpperCase(S)
  181. END (* FirstName *);
  182.  
  183.  
  184. FUNCTION LastName(VAR F : Text) : String;
  185.   (* Retrieve LAST_NAME from current record in file F. *)
  186. VAR
  187.    S : String;
  188.    C : Char;
  189. BEGIN
  190.    S := '';
  191.    C := #$FF;
  192.    Read(F,C);
  193.    WHILE (NOT EoF(F)) AND IsAlpha(C) DO
  194.       BEGIN
  195.          S[0] := Chr(Ord(S[0]) + 1);
  196.          S[Ord(S[0])] := C;
  197.          Read(F,C)
  198.       END;
  199.    LastName := UpperCase(S)
  200. END (* LastName *);
  201.  
  202.  
  203. FUNCTION TestName(VAR F : Text) : String;
  204.   (* Retrieve TEST_NAME from current record in file F. *)
  205. VAR
  206.    S : String;
  207.    C : Char;
  208. BEGIN
  209.    S := '';
  210.    C := #$00;
  211.    Read(F,C);
  212.    WHILE (NOT Eof(F)) AND IsResponseHeader(C) DO
  213.       Read(F,C);
  214.    Read(F,C);
  215.    WHILE (NOT EoF(F)) AND (NOT IsLetter_c(C)) DO
  216.       BEGIN
  217.          S[0] := Chr(Ord(S[0]) + 1);
  218.          S[Ord(S[0])] := C;
  219.          Read(F,C)
  220.       END;
  221.    TestName := UpperCase(S)
  222. END (* TestName *);
  223.  
  224.  
  225. FUNCTION SectionNumber(VAR F : Text) : Integer;
  226.   (* Retrieve SEC_NUM from current record in file F. *)
  227. VAR
  228.    Code : Integer;
  229.    Value : Integer;
  230.    S : String;
  231.    C : Char;
  232. BEGIN
  233.    S := '';
  234.    C := #$00;
  235.    WHILE (NOT Eof(F)) AND IsResponseHeader(C) DO
  236.       Read(F,C);
  237.    Read(F,C);
  238.    FOR Code := 1 TO 2 DO
  239.       BEGIN
  240.          S[0] := Chr(Ord(S[0]) + 1);
  241.          S[Ord(S[0])] := C;
  242.          Read(F,C)
  243.       END;
  244.    Val(S,Value,Code);
  245.    SectionNumber := Value
  246.  
  247. END (* SectionNumber *);
  248.  
  249.  
  250. FUNCTION QuestionStatus(VAR F : Text;
  251.                         VAR Q : Integer;
  252.                         VAR I : Integer;
  253.                         VAR N : Integer;
  254.                         VAR C : Char) : String;
  255.   (* Determine the results of Question Q in current record in F.
  256.      tally I correct responces for N total questions, passing back
  257.      the next field C in record. *)
  258. VAR
  259.    S : String;
  260.    T : String;
  261. BEGIN
  262.    S := '';
  263.    Str(Q,S);
  264.    IF Length(S) < 2 THEN
  265.       S := ' ' + S;
  266.    T[0] := Chr(1);
  267.    T[1] := C;
  268.    T := UpperCase(T);
  269.    Inc(N);
  270.    IF IsNumeric(C) THEN
  271.       BEGIN
  272.          Inc(I);
  273.          QuestionStatus := 'Question ' + S + ' was answered correctly.'
  274.       END
  275.    ELSE
  276.       QuestionStatus := 'Question ' + S + ' was incorrectly answered!   [' + T + ']';
  277.    Inc(Q);
  278.    Read(F,C)
  279. END (* QuestionStatus *);
  280.  
  281.  
  282. PROCEDURE ListEm(VAR F : Text;
  283.                  VAR O : Text;
  284.                  VAR I : Integer;
  285.                  VAR N : Integer);
  286.   (* Step through all the responses until there are no more in F.
  287.      Write a status for the response in O and tally I correct responses
  288.      for N total questions. *)
  289. VAR
  290.    C : Char;
  291.    Q : Integer;
  292.    Waste : 0..10;
  293. BEGIN
  294.    Q := 1;
  295.    C := #$FF;
  296.    C := #$FF;
  297.    FOR Waste := 1 TO 10 DO
  298.       Read(F,C);
  299.    WHILE (NOT EoF(F)) AND (NOT IsSpace(C)) DO
  300.       WriteLn(O,QuestionStatus(F,Q,I,N,C))
  301. END (* ListEm *);
  302.  
  303.  
  304. PROCEDURE DoIt(VAR F,
  305.                O : Text);
  306.   (* List out the information in file F into ASCII text output file O. *)
  307. VAR
  308.    Percentage : Real;
  309.    I : Integer;
  310.    N : Integer;
  311. BEGIN
  312.    WriteLn(O,'────────────── CNE Assessment Test Results ───────────────');
  313.  
  314.    WHILE NOT NoMore(F) DO
  315.       BEGIN
  316.          Percentage := 0.0;
  317.          I := 0;
  318.          N := 0;
  319.  
  320.          WriteLn(O);
  321.          WriteLn(O,'TESTED : ',FirstName(F),' ',LastName(F),'.');
  322.          WriteLn(O);
  323.          WriteLn(O,'COURSE : ',TestName(F),'  SECTION : ',SectionNumber(F));
  324.          WriteLn(O);
  325.          ListEm(F,O,I,N);
  326.          Percentage := I / N * 100;
  327.          WriteLn(O);
  328.          WriteLn(O);
  329.          WriteLn(O,'SCORE :   ',I,' Correct out of ',N,' = ',Percentage:5:2,'%.');
  330.          WriteLn(O);
  331.          WriteLn(O,'──────────────────────────────────────────────────────────')
  332.       END
  333.  
  334. END (* DoIt *);
  335.  
  336.  
  337. BEGIN (* main *)
  338.  
  339.    Salutations;
  340.    OpenFiles(InFile,OutFile);
  341.  
  342.    DoIt(InFile,OutFile);
  343.  
  344.    CloseFiles(InFile,OutFile);
  345.    Goodbyes
  346.  
  347. END.
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.